package com.zxl.always.on.display.configs.bean;

import android.text.TextUtils;

import com.zxl.always.on.display.ApplicationHelper;
import com.zxl.always.on.display.tools.AppUtils;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * Created by Administrator on 2016/10/9.
 */
public class UpgradeBean {

    public int versionCode;

    public String message;

    public boolean isFtp;

    public boolean isUpgrade;

    public String downloadUrl;

    public String marketPackageName;

    public void parseJson(JSONObject jsonObject) {
        versionCode = jsonObject.optInt("vc");
        int current = AppUtils.getVersionCodeByPkgName(ApplicationHelper.getContext(), ApplicationHelper.getContext().getPackageName());
        isUpgrade = versionCode > current;
        message = jsonObject.optString("msg");

        downloadUrl = jsonObject.optString("ftp");

        JSONArray market = jsonObject.optJSONArray("market");
        if (market != null) {
            for (int i = 0; i < market.length(); i++) {
                String packageName = market.optString(i);
                if (AppUtils.isAppExist(ApplicationHelper.getContext(), packageName)) {
                    marketPackageName = packageName;
                    break;
                }
            }
        }
        isFtp = TextUtils.isEmpty(marketPackageName);
    }

}
